import KoaRouter from 'koa-router';

const router = new KoaRouter();

import { HttpUtil } from '../../utils/http.util';
const baseUrl = 'https://172.35.0.2'
router.prefix('/');
router.get(`/api/eks-secure/v1/clusters`, async (ctx, next) => {
    const response: any = await HttpUtil.request({
        url: baseUrl + ctx.request.url,
        method: ctx.req.method,
        headers: { Cookie: ctx.header.cookie }
    });

    // ctx.cookies.set('df', 'df', {})

    // ctx.set['set-cookie'] = [ctx.header.cookie, 'eks=eks'].join(';');
    // ctx.response.set('set-cookie', [ctx.header.cookie, 'login_region=eks'])
    // ctx.cookies.set('eks', 'eks');
    // ctx.response.type = 'application/json';
    // ctx.response.body = { code: '0', data: [{ clusterName: 'cluster-name', status: 'Healthy' }] };
    ctx.response.body = response.body;
});

router.get(`/api/eks-secure/v1/clusters/:clusterName/overview`, async (ctx, next) => {
    const name = ctx.params.clusterName
    console.log(name, ctx.request.url);
    const response: any = await HttpUtil.get(baseUrl + ctx.request.url, {
        headers: { Cookie: ctx.request.header.cookie },
        strictSSL: false
    });
    ctx.response.type = 'application/json';
    ctx.response.body = response.body;
});
router.get(`/api/eks-secure/v1/clusters/:name`, async (ctx, next) => {
    console.log(JSON.stringify(ctx.request));
    const name = ctx.params.name
    ctx.response.type = 'application/json';
    ctx.response.body = { code: '0', data: [{ clusterName: 'cluster-name', status: 'Healthy' }] };
});

router.patch(`/api/demo`, async (ctx, next) => {
    console.log('-----------------patch-------------------');
    console.log(JSON.stringify(ctx.request['body']));
    ctx.response.type = 'application/json';
    ctx.response.body = { code: 200, data: [{ clusterName: 'cluster-name', status: 'Healthy' }] };
});
router.post(`/lapi/demo`, async (ctx, next) => {
    console.log('-----------------post-------------------');
    console.log(JSON.stringify(ctx.request['body']), ctx.URL);
    ctx.response.type = 'application/json';
    ctx.response.body = { code: 200, data: [{ clusterName: 'cluster-name', status: 'Healthy' }] };
});

router.get(`/api/demo`, async (ctx, next) => {
    const name = ctx.params.name
    ctx.response.type = 'application/json';
    ctx.response.body = { code: 200, data: [{ clusterName: 'cluster-name', status: 'Healthy' }] };
});

module.exports = router;